/*
 * 快视图底图配置工具
 */
var layerCfgUtil = {
		layerUrl : CafeJS.CXT+"static/widgets/cafejs/script/utils/layerConfig/layer-config.json",//底图地址
		layerObj : {}//底图对象
};

//初始化底图配置
layerCfgUtil.initLayerCfg = function(){
    $.ajaxSettings.async = false;
	$.getJSON(this.layerUrl, function(jsonData){
        $.ajaxSettings.async = true;
		$.each(Object.keys(jsonData),function(i,s){
			var area = jsonData[s];
			$.each(Object.keys(area),function(j,a){
				layerCfgUtil.layerObj[s+"-"+a] = area[a];
			});
		});
	});
};
/**
 * 获取底图
 * area 范围
 * size 尺寸
 */
layerCfgUtil.getLayers = function(area,size){
	return this.layerObj[size+"-"+area];
};

/**
 * 构造底图
 * container 容器
 * area 范围
 * size 尺寸
 * isNoMask 是否不显示掩膜
 */
layerCfgUtil.bulidLayers = function(container,area,size,isNoMask){
	var sizes = size.split("_");
	var w = sizes[0];
	var h = sizes[1];
	if(4 == sizes.length){
        w = sizes[2];
        h = sizes[3];
	}
	$.each(this.getLayers(area,sizes[0]+"_"+sizes[1]),function(){
		if(this.isDisplay){
			var $img = $('<img>');
			if(this.isLatlon){
				$img.css({
					"width" : "100%",
					"height" : "100%",
					"top" : 0,
					"left" : 0
				})
			}else{
				$img.css({
					"width" : w + "px",
					"height" : h + "px",
					"top" : "1px",
					"right" : "1px"
				})
			}
			$img.addClass(this.cls).css("z-index",this.zIndex).attr("src",CafeJS.CXT+this.src);
			if(!isNoMask || -1 == this.src.indexOf("mask")){
                container.append($img);
			}
		}
	});
};
layerCfgUtil.bulidLayers2 = function(container,area,size){
	$.each(this.getLayers(area,size),function(){
		if(this.isDisplay){
			var $img = $('<img>');
			if(this.isLatlon){
				$img.addClass("latlon-layers")
			}
			$img.css("z-index",this.zIndex).attr("src",CafeJS.CXT+this.src);
			container.append($img);
		}
	});
};

layerCfgUtil.initLayerCfg();

